<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>su</title>
  </head>
  <body>
    <script type="text/javascript">
      'use strict'
      var data = {
        title: 'html',
        mandlate: {
          value: 'learn',
          href: 'http:baidu.com'
        },
        blockA: {
          fn: () => {}
          // blockA: 'blockA'
        },
        list: {
          header: {
            chart: 'utf-8',
            blockA: {
              href: '我是header的',
              blockA: {
                a: '你好',
                b: () => {}
              }
            },
            a: {
              a: {
                blockA: '我是AAAAA的'
              }
            }
          },
          blockA: {
            href: '我是list下的'
          }
        },
        href: '我是没有裤脚'
      }

      Object.isObject = args => Object.prototype.toString.call(args) === '[object Object]'

      function setObjectAlias({ obj = {}, alias = '', parentAlias = '' }) {
        if (Object.isObject(obj)) {
          obj._alias = [parentAlias, alias].filter(v => v).join('|')
          Object.keys(obj).forEach(key => {
            setObjectAlias({
              obj: obj[key],
              alias: key,
              parentAlias: obj._alias
            })
          })
        }
      }

      // ---------------------代码start------------------------
      function getProperty({ obj = {}, field = '', pField = [], result = [] }) {
        if (Object.isObject(obj)) {
          if (obj.hasOwnProperty(field)) {
            const value = {
              path: obj[field]._alias,
              value: JSON.parse(JSON.stringify(obj[field]))
            }
            if (!Object.isObject(obj[field])) {
              value.path = obj._alias + '|' + field
            }
            result.push(value)
          }
          Object.keys(obj).forEach(key => {
            getProperty({ obj: obj[key], field, pField, result })
          })
        }
        return result
      }

      setObjectAlias({
        obj: data,
        parentAlias: ''
      })

      console.log(data)
      const result = getProperty({ obj: data, field: 'blockA' }).map(v => ({
        keys: v.path.split('|'),
        ...v
      }))

      console.log('结果', result)
      // ---------------------代码end------------------------
    </script>
  </body>
</html>
